<template>
	<view class="page-container">
		<view class="top">
			<view class="back-btn" @click="backPage()">
				<view class="back-icon"></view>
			</view>
			<uni-search-bar bgColor="#fff" class="uni-mt-10" radius="100" placeholder="请输入要搜索的内容" clearButton="none" @confirm="search"
				cancelButton="none">
			</uni-search-bar>
		</view>
		<view class="record-list">
			<view class="record-item" v-for="record in vRecords" :key="record.id">
				<view class="record-title">{{ record.servicesName }}</view>
				<view class="record-user">下单用户：{{ record.username }}</view>
				<view class="record-amount">实付金额：¥{{ record.price }}</view>
				<view class="record-time">核销时间：{{ record.time }}</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue';
	import {
		onLoad
	} from '@dcloudio/uni-app'
	import request from '../../util/request';
	import baseUrl from '../../util/urlConfig';

	const name = ref('SalesRecord');
	const vRecords = ref([])
	const query = ref({
		orderId: 0,
		ids: []
	})
	const services = ref([])
	// const servicesName = ref('')
	
	const records = ref([{
			title: '普通洗车、机油、工时',
			user: '张三',
			amount: '32.00',
			time: '2022-10-12 11:09'
		},
		{
			title: '普通洗车、机油、工时',
			user: '张三',
			amount: '32.00',
			time: '2022-10-12 11:09'
		},
		{
			title: '普通洗车、机油、工时',
			user: '张三',
			amount: '32.00',
			time: '2022-10-12 11:09'
		}
	])
	
	function search() {
		console.log(666)
	}

	function backPage() {
		uni.navigateBack()
	}

	function getVRecords() {
		request({
			url: baseUrl + '/wwc/vRecord/list',
			method: 'GET',
			data: null,
			success(res) {
				vRecords.value = res.data.rows;
				console.log(vRecords.value)

				vRecords.value.forEach((item) => {
					// console.log(item.mid+item.oid);
					query.value.orderId = item.oid;
					request({
						url: baseUrl + '/wwc/orders/serviceListwwc',
						method: 'GET',
						data: query.value,
						success(res) {
							// console.log(res.data.data)
							query.value.ids = res.data.data;
							//得到每个订单的服务id后，根据多个服务id得到对应的服务名
							request({
								url: baseUrl + '/xyq/details/listwwc',
								method: 'POST',
								data: query.value, //传对象
								success(res) {
									console.log(res.data);
									services.value = res.data.data;
									// services.value.forEach((it)=>{
									// 	console.log('直接输出:', it.name);                     // 字符串
									// 	console.log('类型检测:', typeof it.name);            // 应该显示 "string"
									// 	console.log('字符串长度:', it.name.length);         // 数字
									// })
									item.servicesName = services.value.map(it=>it.name).join(',');
									console.log(item.servicesName);
									
									// const testNames = services.value.map(it => it.name).join(',');
									// console.log('拼接结果类型:', typeof testNames);      // 应该显示 "string"
									// console.log('拼接结果:', testNames);                 // 应该显示字符串
									
									// item.servicesName = testNames;
									// console.log('赋值后类型:', typeof item.servicesName); // 检查是否变为object
									// console.log('赋值后结果:', item.servicesName);
					
								}
							});
							
						}
					});

				})


			}
		});
	}
	getVRecords();
</script>

<style scoped>
	.page-container {
		width: 100%;
	}

	.map {
		width: 100%;
		height: 300rpx;
	}

	.card {
		color: red;
		padding-bottom: 100rpx;
	}

	.top {
		width: 100%;
		height: 400rpx;
		background-color: #0091ff;
		background-size: 100%;
	}

	.title {
		padding: 30rpx 0rpx;
		font-size: 30rpx;
		text-align: center;
		color: white;
		font-weight: bold;
	}

	.im {
		width: 40rpx;
		height: 40rpx;
		background-color: skyblue;
		padding: 20rpx;
		border-radius: 20rpx;
	}

	.grid-item-box {
		flex: 1;
		/* // position: relative; */
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 15px 0;
	}

	.uni-mt-10 {
		margin-top: 50px;
	}

	.sales-record {
		padding: 20rpx;
		background-color: #f5f5f5;
	}

	.search-box {
		position: relative;
		margin-bottom: 20rpx;
	}

	.search-input {
		width: 100%;
		height: 80rpx;
		background: #FFFFFF;
		border-radius: 40rpx;
		padding: 0 80rpx 0 30rpx;
		font-size: 28rpx;
	}

	.search-icon {
		position: absolute;
		right: 30rpx;
		top: 50%;
		transform: translateY(-50%);
		font-size: 32rpx;
		color: #999;
	}

	.record-list {
		/* 	display: flex;
	justify-content: center; */
		margin-top: -20%;
		width: 95%;
		margin-left: 2%;
	}

	.record-item {
		background: #FFFFFF;
		border-radius: 20rpx;
		padding: 30rpx;
		margin-bottom: 50rpx;
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
	}

	.record-title {

		font-size: 32rpx;
		font-weight: 500;
		color: #333;
		margin-bottom: 20rpx;
	}

	.record-user {
		font-size: 28rpx;
		color: #666;
		margin-bottom: 10rpx;
	}

	.record-amount {
		font-size: 28rpx;
		color: #666;
		margin-bottom: 10rpx;
	}

	.record-time {
		font-size: 24rpx;
		color: #999;
	}

	.back-btn {
		margin-left: 20rpx;
		width: 50rpx;
		height: 50rpx;
		position: relative;
	}

	.back-icon {
		width: 30px;
		height: 30px;
	}

	.back-icon::before {
		content: "";
		position: absolute;
		width: 20px;
		height: 2px;
		background-color: #fff;
		top: 80rpx;
		left: 47rpx;
		transform: translate(-50%, -50%);
	}

	.back-icon::after {
		content: "";
		position: absolute;
		width: 10px;
		height: 10px;
		border-left: 2px solid #fff;
		border-bottom: 2px solid #fff;
		transform: rotate(45deg);
		top: 70rpx;
		left: 30rpx;
	}
</style>